import * as config from '@/config/config.js'
import store from '@/store/index.js'

export function jumpToLogin() {
	console.log("跳转登录被触发");
	store.dispatch('user/logout');
	uni.showToast({
		title: '请重新登录!',
		icon: 'none',
		duration: 1000,
		success: function(res) {
			setTimeout(() => {
				console.log("开始执行跳转")
				uni.reLaunch({
					url: '/pages/login/index'
				})
			}, 1000)
		}
	})
}


export function userCheckInfoImgUrl(imgPath) {
	if(!imgPath) {
		return undefined;
	}
  return config.fileBaseUrl + 'api/UserCheckInfo/' + imgPath;
}

export function userCheckInfoMinImgUrl(imgPath) {
  if (!imgPath) {
    return undefined
  }
  var suffixIndex = imgPath.lastIndexOf('.')
  return suffixIndex >= 0
    ? config.fileBaseUrl + 'api/UserCheckInfo/' + imgPath.substr(0, suffixIndex) + '_min' + imgPath.substr(suffixIndex)
    : config.fileBaseUrl + 'api/UserCheckInfo/' + imgPath;
}


export function costInfoImgUrl(imgPath) {
	if(!imgPath) {
		return undefined;
	}
  return config.fileBaseUrl + 'api/CostInfo/' + imgPath;
}

export function costInfoMinImgUrl(imgPath) {
  if (!imgPath) {
    return undefined
  }
  var suffixIndex = imgPath.lastIndexOf('.')
  return suffixIndex >= 0
    ? config.fileBaseUrl + 'api/CostInfo/' + imgPath.substr(0, suffixIndex) + '_min' + imgPath.substr(suffixIndex)
    : config.fileBaseUrl + 'api/CostInfo/' + imgPath;
}


export function projectItemInfoImgUrl(imgPath) {
	if(!imgPath) {
		return undefined;
	}
  return config.fileBaseUrl + 'api/ProjectItemInfo/' + imgPath;
}

export function projectItemInfoMinImgUrl(imgPath) {
  if (!imgPath) {
    return undefined
  }
  var suffixIndex = imgPath.lastIndexOf('.')
  return suffixIndex >= 0
    ? config.fileBaseUrl + 'api/ProjectItemInfo/' + imgPath.substr(0, suffixIndex) + '_min' + imgPath.substr(suffixIndex)
    : config.fileBaseUrl + 'api/ProjectItemInfo/' + imgPath;
}


export function addMin(imgUrl) {
	if(!imgUrl || imgUrl === "") {
		return undefined
	}
	var suffixIndex = imgUrl.lastIndexOf('.');
	if(suffixIndex < 0) {
		return imgUrl;
	}
	return imgUrl.substr(0, suffixIndex) + '_min' + imgUrl.substr(suffixIndex)
}

export function removeMin(imgUrl) {
	if(!imgUrl || imgUrl === "") {
		return undefined
	}
	var minIndex = imgUrl.lastIndexOf("_min");
	if(minIndex < 0) {
		return imgUrl;
	}
	return imgUrl.substr(0, minIndex - 1) + imgUrl.substr(minIndex + 3);
}

